package com.example.administrator.helloworld;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * Created by Administrator on 2015/3/30 0030.
 */
public class TestAdapterActivity extends Activity{
    private ListView listView;
    private ArrayAdapter<String> arr_adapter;
    private SimpleAdapter simp_adapter;
    private List<Map<String,Object>> dataList;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.adapter_test);//关联layout
        listView= (ListView) findViewById(R.id.lv);
        String[] arr_data={"sad.","sad..","sad...","sad...."};
        dataList=new ArrayList<Map<String,Object>>();
        arr_adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arr_data);
        simp_adapter=new SimpleAdapter(this,getData(),R.layout.item,new String[] {"pic","text"},new int[]{R.id.iv,R.id.tv});
        listView.setAdapter(simp_adapter);//arr_adapter
    }

    private List<? extends Map<String, ?>> getData() {
        for(int i=0;i<20;i++){
            Map<String,Object>map=new HashMap<String,Object>();
            map.put("pic",R.drawable.myface);
            map.put("text","蛤蛤蛤蛤"+i);
            dataList.add(map);
        }
        return dataList;
    }
}
